package com.cskaoyan.controller.wx_storage;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.admin.Storage;
import com.cskaoyan.bean.wx_resp.WxRespVo;
import com.cskaoyan.service.admin.StorageService;
import com.cskaoyan.utils.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * 类<code>Doc</code>用于：TODO
 *
 * @author Acher
 * @version 1.0
 * @date 2021-10-23
 */
@RequestMapping("wx/storage")
@RestController
public class WxStorageController {

    @Autowired
    StorageService storageService;

    @PostMapping("upload")
    // http://localhost:8083/wx/storage/upload
    public WxRespVo upload(@RequestParam MultipartFile file, HttpServletRequest req) {
        Storage storage = FileUploadUtils.getStorageByFileUpload(file);
        if (!storageService.create(storage)) return WxRespVo.error("添加失败");
        return WxRespVo.ok(storage);
    }
}
